const router = require('koa-router')()
const Mock = require('mockjs');

const { tabs } = Mock.mock({
  "tabs|5": [{
    "id": "@id",
    "title": "@ctitle(2)",
    "children|1000": [{
      "image": "@image(150x120, @color, item)",
      "title": "@ctitle",
      "desc": "@cword(10, 20)",
      "id": "@id",
    }]
  }]
})

router.get('/tabs', ctx => {
  // while(true) {
  //   console.log(1)
  // }

  ctx.body = {
    code: 200,
    data: tabs
  }
})

const { list } = Mock.mock({
  "list|1000": [{
    "id|+1": 1,
    "type|1": ["手机", "电脑", "电视", "衣服", "推荐"],
    "image": "@image(150x120, @color, item)",
    "title": "@ctitle",
    "desc": "@cword(10, 20)",
  }]
})

router.get('/list', ctx => {
  const { type = '推荐', pageCode = 1, pageSize = 10 } = ctx.request.query;
  const newList = list.filter(v => v.type === type);
  const data = newList.slice((pageCode -1)* pageSize, pageCode * pageSize);
  ctx.body = {
    code: 200,
    data: data
  }
})



module.exports = router
